package com.gegao.practise.lanuchcount;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;

import com.gegao.practise.R;


public class TestLaunchCount extends Activity {
    Button mBt1;
    Button mBt2;
    
    FrameLayout frameLayout;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        increaseLaunchCount();
        frameLayout = (FrameLayout) getWindow()
                .getDecorView().findViewById(android.R.id.content);
        
        setContentView(R.layout.two_button);
        mBt1 = (Button)findViewById(R.id.bt1);
        mBt1.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                OrangeGestureHelp.getInstantce(TestLaunchCount.this, frameLayout).onPageFinished(false);
            }
        });
        
        mBt2 = (Button)findViewById(R.id.bt2);
        mBt2.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                OrangeGestureHelp.getInstantce(TestLaunchCount.this, frameLayout).setPrefsProperty(OrangeGestureHelp.ALREADY_USE_JIANBAO_GESTURE, true);
            }
            
        });
    }
    
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
    
    private void increaseLaunchCount() {
        SharedPreferences prefs =
                getSharedPreferences(OrangeGestureHelp.GESTURE_SHARED_FILE, 0);
        int launch_count = prefs.getInt(OrangeGestureHelp.APP_LAUNCH_COUNT, 0) + 1;
        prefs.edit().putInt(OrangeGestureHelp.APP_LAUNCH_COUNT,
                launch_count).commit();
        OrangeGestureHelp.getInstantce(TestLaunchCount.this, frameLayout).setPrefsProperty(OrangeGestureHelp.SHOW_JIANBAO_EVERY_LAUNCH, true);
    }

}
